package com.cch.utils;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.InetAddress;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.regex.Pattern;

public class SysUtil {
    private static final Logger logger = Logger.getLogger(SysUtil.class);
    public static final String EMPTY_STRING = "";


    //0相等，1大于，-1小于，-2异常
    public static int compareVersion(String version, String currentVersion) {
        int ret = -2;
        if (SysUtil.isNotEmpty(version) && SysUtil.isNotEmpty(currentVersion)) {
            version = version.trim();
            currentVersion = currentVersion.trim();
            if (version.equals(currentVersion))
                return 0;

            String[] dbVersionArray = version.split("\\.");
            String[] currentVersionArray = currentVersion.split("\\.");

            if (dbVersionArray.length != currentVersionArray.length)
                return -2;

            for (int index = 0; index < dbVersionArray.length; index++) {
                String dbV = dbVersionArray[index];
                String cv = currentVersionArray[index];
                if (StringUtils.isNumeric(dbV) && StringUtils.isNumeric(cv)) {
                    try {
                        Integer db = Integer.parseInt(dbV);
                        Integer c = Integer.parseInt(cv);
                        if (db > c)
                            return 1;
                        if (db < c)
                            return -1;
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                        return -2;
                    }
                } else {
                    return -2;
                }
            }
        }
        return ret;
    }

    public static String formatValue(int i) {
        return String.format("%1$,02d", i);
    }

    public static String getDecimalFormatValue(double p) {
        DecimalFormat nf = (DecimalFormat) NumberFormat.getPercentInstance();
        nf.applyPattern("00.00%"); //00表示小数点2位
        nf.setMaximumFractionDigits(2); //2表示精确到小数点后2位
        return nf.format(p);
    }

    public static String defaultString(String str) {
        return isEmpty(str) ? "default" : str;
    }

    public static boolean isEmpty(String[] array) {
        for (String str : array) {
            if (isEmpty(str))
                return true;
        }
        return false;
    }

    /**
     * 是否为空
     *
     * @param str
     * @return
     * @author 魏柱
     * @date 2013-3-28 下午4:30:02
     */
    public static boolean isEmpty(String str) {
        if (str == null || str.trim().length() == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    /**
     * 截取字符串
     *
     * @return
     * @author stone
     * @time 2012-11-13下午10:23:46
     */
    public static String substring(String str, int length, String s) {
        if (str == null || str.isEmpty() || str.length() < length) {
            return str;
        }
        str = str.substring(0, length - 1);
        return str + s;
    }

    /**
     * 生成随机字符串
     *
     * @return String
     */
    public static String UUID() {
        UUID uuid = UUID.randomUUID();
        String str = uuid.toString();
        str = str.replaceAll("-", "");
        return str;
    }

    /**
     * 对原始字符串进行编码转换，如果失败，返回原始的字符串
     *
     * @param s            原始字符串
     * @param srcEncoding  源编码方式
     * @param destEncoding 目标编码方式
     * @return 转换编码后的字符串，失败返回原始字符串
     */
    public static String getString(String s, String srcEncoding,
                                   String destEncoding) {
        try {
            return new String(s.getBytes(srcEncoding), destEncoding);
        } catch (UnsupportedEncodingException e) {
            return s;
        }
    }

    /**
     * 根据某种编码方式将字节数组转换成字符串
     *
     * @param b        字节数组
     * @param encoding 编码方式
     * @return 如果encoding不支持，返回一个缺省编码的字符串
     */
    public static String getString(byte[] b, String encoding) {
        try {
            return new String(b, encoding);
        } catch (UnsupportedEncodingException e) {
            return new String(b);
        }
    }

    /**
     * 根据某种编码方式将字节数组转换成字符串
     *
     * @param b        字节数组
     * @param offset   要转换的起始位置
     * @param len      要转换的长度
     * @param encoding 编码方式
     * @return 如果encoding不支持，返回一个缺省编码的字符串
     */
    public static String getString(byte[] b, int offset, int len,
                                   String encoding) {
        try {
            return new String(b, offset, len, encoding);
        } catch (UnsupportedEncodingException e) {
            return new String(b, offset, len);
        }
    }

    /**
     * 截取字符串，包含中文
     *
     * @return
     */
    public final static String cutTrueLength(String strContent,
                                             int maxTrueLength) {
        if (strContent == null || maxTrueLength <= 0) {
            return "";
        }

        int trueLen = trueLength(strContent);
        String strNew = strContent;
        if (trueLen > maxTrueLength) {
            for (int i = strContent.length() - 1; i > 0; i--) {
                strNew = strContent.substring(0, i);

                if (trueLength(strNew) == maxTrueLength) {
                    break;
                } else if (trueLength(strNew) < maxTrueLength) {
                    strNew += "";
                    break;
                }
            }
        }

        return strNew + "...";
    }

    /**
     * 字符串长度，包含中文
     *
     * @param strContent
     * @return
     */
    public final static int trueLength(String strContent) {
        int lengthTotal = 0;// 长度总计

        int n = strContent.length();

        String strWord = "";

        int asc;

        for (int i = 0; i < n; i++) {
            strWord = strContent.substring(i, i + 1);
            asc = strWord.charAt(0);
            if (asc < 0 || asc > 127)
                lengthTotal = lengthTotal + 2;
            else
                lengthTotal = lengthTotal + 1;
        }

        return lengthTotal;
    }

    public static String abbreviate(String str, int width, String ellipsis) {
        if (str == null || "".equals(str)) {
            return "";
        }

        int d = 0; // byte length
        int n = 0; // char length
        for (; n < str.length(); n++) {
            d = (int) str.charAt(n) > 256 ? d + 2 : d + 1;
            if (d > width) {
                break;
            }
        }

        if (d > width) {
            n = n - ellipsis.length() / 2;
            return str.substring(0, n > 0 ? n : 0) + ellipsis;
        }

        return str = str.substring(0, n);
    }

    /**
     * @return String Object
     */
    public static String Html2Text(String inputString) {
        String htmlStr = inputString; // 含html标签的字符串
        String textStr = "";
        Pattern p_script;
        java.util.regex.Matcher m_script;
        Pattern p_style;
        java.util.regex.Matcher m_style;
        Pattern p_html;
        java.util.regex.Matcher m_html;

        Pattern p_html1;
        java.util.regex.Matcher m_html1;

        try {
            String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; // 定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script>
            // }
            String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; // 定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style>
            // }
            String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
            String regEx_html1 = "<[^>]+";
            p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
            m_script = p_script.matcher(htmlStr);
            htmlStr = m_script.replaceAll(""); // 过滤script标签

            p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
            m_style = p_style.matcher(htmlStr);
            htmlStr = m_style.replaceAll(""); // 过滤style标签

            p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
            m_html = p_html.matcher(htmlStr);
            htmlStr = m_html.replaceAll(""); // 过滤html标签

            p_html1 = Pattern.compile(regEx_html1, Pattern.CASE_INSENSITIVE);
            m_html1 = p_html1.matcher(htmlStr);
            htmlStr = m_html1.replaceAll(""); // 过滤html标签

            textStr = htmlStr;

        } catch (Exception e) {
            logger.error("Html2Text error!", e);
        }

        return textStr;// 返回文本字符串
    }


    @SuppressWarnings("rawtypes")
    public static boolean isSetEqual(Set set1, Set set2) {

        if (set1.size() != set2.size()) {
            return false;
        }

        Iterator ite1 = set1.iterator();
        Iterator ite2 = set2.iterator();

        boolean isFullEqual = true;
        while (ite1.hasNext()) {
            if (!set2.contains(ite2.next())) {
                isFullEqual = false;
            }
        }

        return isFullEqual;
    }

    //全部不是空 返回true
    public static boolean isAllNotEmpty(String... strs) {
        if (ArrayUtils.isEmpty(strs)) return false;
        for (String str : strs) {
            if (isEmpty(str)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isAllEmpty(String... strs) {
        return !isNotAllEmpty(strs);
    }

    //有一个不是空 返回true
    public static boolean isNotAllEmpty(String... strs) {
        if (ArrayUtils.isEmpty(strs)) return false;
        for (String str : strs) {
            if (isNotEmpty(str)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 深度克隆对象
     */
    @SuppressWarnings("unchecked")
    public static <T extends Serializable> T deepClone(T t) throws Exception {

        // 将对象写到流里
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream oo = new ObjectOutputStream(bo);
        oo.writeObject(t);

        // 从流里读出来
        ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
        ObjectInputStream oi = new ObjectInputStream(bi);
        return (T) (oi.readObject());
    }

    /**
     * 除去Map中的空值和指定参数Key
     *
     * @param params
     * @return 去掉空值与指定参数Key后的新Map
     */
    public static Map<String, String> paraFilter(Map<String, String> params, String... filterKeys) {
        Map<String, String> result = new HashMap<String, String>();

        if (params == null || params.size() <= 0) {
            return result;
        }
        for (String key : params.keySet()) {
            String value = params.get(key);
            if (value == null || value.equals("") || ArrayUtils.contains(filterKeys, key)) {
                continue;
            }
            result.put(key, value);
        }

        return result;
    }


    /**
     * 把Map所有元素排序，并按照“参数=参数值”的模式用“&”字符拼接成字符串
     *
     * @param params 需要排序并参与字符拼接的参数组
     * @return 拼接后字符串
     */
    public static String createLinkString(Map<String, String> params) {

        List<String> keys = new ArrayList<String>(params.keySet());
        Collections.sort(keys);
        String preStr = "";
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            String value = params.get(key);
            if (i == keys.size() - 1) {//拼接时，不包括最后一个&字符
                preStr = preStr + key + "=" + value;
            } else {
                preStr = preStr + key + "=" + value + "&";
            }
        }

        return preStr;
    }

    /**
     * 获取一个四位随机数，并且四位数不重复
     *
     * @return String
     */
    public static String getRandomNumber(int size) {
        // 使用SET以此保证写入的数据不重复
        Set<Integer> set = new HashSet<Integer>();
        // 随机数
        Random random = new Random();

        while (set.size() < size) {
            // nextInt返回一个伪随机数，它是取自此随机数生成器序列的、在 0（包括）
            // 和指定值（不包括）之间均匀分布的 int 值。
            set.add(random.nextInt(10));
        }
        return StringUtils.join(set, "");
    }

    public static String getRandomNumber() {
        return getRandomNumber(4);
    }

    public static String toUtf8String(String str) {
        try {
            if (str != null)
                return new String(str.getBytes(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        return null;
    }

    /**
     * 设置下载文件中文件的名称
     *
     * @param filename
     * @param request
     * @return
     */
    /**
     * 设置下载文件中文件的名称
     *
     * @param filename
     * @param request
     * @return
     */
    public static String encodeFilename(String filename, HttpServletRequest request) {
        /**
         * 获取客户端浏览器和操作系统信息
         * 在IE浏览器中得到的是：User-Agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; Alexa Toolbar)
         * 在Firefox中得到的是：User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.7.10) Gecko/20050717 Firefox/1.0.6
         */
        String agent = request.getHeader("USER-AGENT");
        try {
            if ((agent != null) && (-1 != agent.indexOf("MSIE"))) {
                String newFileName = URLEncoder.encode(filename, "UTF-8");
                newFileName = StringUtils.replace(newFileName, "+", "%20");
                if (newFileName.length() > 150) {
                    newFileName = new String(filename.getBytes("GB2312"), "ISO8859-1");
                    newFileName = StringUtils.replace(newFileName, " ", "%20");
                }
                return newFileName;
            }
            if ((agent != null) && (-1 != agent.indexOf("Mozilla")))
                //return MimeUtility.encodeText(filename, "UTF-8", "B");
                return new String(filename.getBytes("utf-8"), "iso-8859-1");
            return filename;
        } catch (Exception ex) {
            return filename;
        }
    }

    public static String objectToString(Object obj) {
        if (obj == null) {
            return EMPTY_STRING;
        }
        return truncValue(obj.toString());
    }

    public static String truncValue(String str) {
        if (isEmpty(str)) {
            return EMPTY_STRING;
        }
        return str;
    }

    public static String trimValue(String str) {
        if (str == null) {
            return str;
        }
        return str.trim();
    }

    /**
     * 去除字符串中头部和尾部所包含的空格（包括:空格(全角，半角)\制表符、换页符 换行等）
     *
     * @param str
     * @return
     */
    public static String trimQJValue(String str) {
        if (str == null) {
            return str;
        }
        String result = str.trim();
        if (!"".equals(str)) {
            result = str.replaceAll("^[　*| *| *]*", "").replaceAll("[　*| *| *]*$", "").replaceAll("\\s*|\t|\r|\n", "");
        }
        return result;
    }

    public static String valueOf(Object obj) {
        if (obj == null) {
            return "";
        }
        return obj.toString();
    }

    public static String retainsArray(String a, String b) {
        StringBuffer al = new StringBuffer();
        for (String at : a.split(",")) {
            for (String bt : b.split(",")) {
                if (at.equals(bt)) {
                    al.append(at + ",");
                    break;
                }
            }
        }
        if (al.toString().length() > 0)
            al.setLength(al.length() - 1);
        return al.toString();
    }

    public static String convertString(String src, String APISrcCharSet, String APIDestCharSet) {
        String ret = src;
        if (src != null) {
            try {
                ret = new String(src.getBytes(APISrcCharSet), APIDestCharSet);
            } catch (UnsupportedEncodingException e) {
                ret = src;
            }
        }
        return ret;
    }


    /**
     * 以行为单位读取文件，常用于读面向行的格式化文件
     */
    @SuppressWarnings("unused")
    public static List<String> readFileByLines(String fileName) {
        List<String> lineList = new ArrayList<String>();
        File file = new File(fileName);
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            int line = 1;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                // 显示行号
//                System.out.println("line " + line + ": " + tempString);
                lineList.add(tempString);
                line++;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
        return lineList;
    }


    /**
     * 将InputStream转换成String
     *
     * @param in InputStream
     * @return String
     * @throws Exception
     */
    public static String inputStreamTOString(InputStream in) throws Exception {
        int BUFFER_SIZE = 4096;
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] data = new byte[BUFFER_SIZE];
        int count = -1;
        while ((count = in.read(data, 0, BUFFER_SIZE)) != -1)
            outStream.write(data, 0, count);

        data = null;
        return new String(outStream.toByteArray(), "UTF-8");
    }

    public static String exceptionToString(Exception e) {
        StringWriter writer = new StringWriter();
        e.printStackTrace(new PrintWriter(writer, true));
        return writer.toString();
    }

    public static String throwableToString(Throwable t) {
        StringWriter writer = new StringWriter();
        t.printStackTrace(new PrintWriter(writer, true));
        return writer.toString();
    }


    /**
     * 默认false  关闭
     *
     * @return
     */
    public static boolean isScheduler() {
        return true;
    }

    /**
     * 知识的补充
     *
     * InetAddress 继承自 java.lang.Object类
     * 它有两个子类：Inet4Address 和 Inet6Address
     * 此类表示互联网协议 (IP) 地址。
     *
     * IP 地址是 IP 使用的 32 位或 128 位无符号数字，
     * 它是一种低级协议，UDP 和 TCP 协议都是在它的基础上构建的。
     *
     * ************************************************
     * 主机名就是计算机的名字（计算机名），网上邻居就是根据主机名来识别的。
     * 这个名字可以随时更改，从我的电脑属性的计算机名就可更改。
     *  用户登陆时候用的是操作系统的个人用户帐号，这个也可以更改，
     *  从控制面板的用户界面里改就可以了。这个用户名和计算机名无关。
     */

    /**
     * 获取本机的IP
     *
     * @return Ip地址
     */
    public static String getLocalHostIP() {
        String ip;
        try {
            /**返回本地主机。*/
            InetAddress addr = InetAddress.getLocalHost();
            /**返回 IP 地址字符串（以文本表现形式）*/
            ip = addr.getHostAddress();
        } catch (Exception ex) {
            ip = "";
        }

        return ip;
    }

    /**
     * 或者主机名：
     *
     * @return
     */
    public static String getLocalHostName() {
        String hostName;
        try {
            /**返回本地主机。*/
            InetAddress addr = InetAddress.getLocalHost();
            /**获取此 IP 地址的主机名。*/
            hostName = addr.getHostName();
        } catch (Exception ex) {
            hostName = "";
        }

        return hostName;
    }

    /**
     * 获得本地所有的IP地址
     *
     * @return
     */
    public static String[] getAllLocalHostIP() {

        String[] ret = null;
        try {
            /**获得主机名*/
            String hostName = getLocalHostName();
            if (hostName.length() > 0) {
                /**在给定主机名的情况下，根据系统上配置的名称服务返回其 IP 地址所组成的数组。*/
                InetAddress[] addrs = InetAddress.getAllByName(hostName);
                if (addrs.length > 0) {
                    ret = new String[addrs.length];
                    for (int i = 0; i < addrs.length; i++) {
                        /**.getHostAddress()   返回 IP 地址字符串（以文本表现形式）。*/
                        ret[i] = addrs[i].getHostAddress();
                    }
                }
            }

        } catch (Exception ex) {
            ret = null;
        }

        return ret;
    }

    public static String getFirstNotEmptyStr(String... strArr) {
        if (ArrayUtils.isNotEmpty(strArr)) {
            for (String str : strArr) {
                if (StringUtils.isNotBlank(str)) {
                    return str;
                }
            }
        }
        return null;
    }
    /**
     * 字符在字符串中出现的次数
     *
     * @param string
     * @param a
     * @return
     */
    public static int occurTimes(String string, String a) {
        int pos = -2;
        int n = 0;

        while (pos != -1) {
            if (pos == -2) {
                pos = -1;
            }
            pos = string.indexOf(a, pos + 1);
            if (pos != -1) {
                n++;
            }
        }
        return n;
    }
//    public static void main(String[] args) throws Exception {
//        System.out.println(DateUtil.getCurrentDay());
//        System.out.println(DateUtil.getCurrentHour());
//        String[] testStrArray = new String[]{"2.1.0,2.1.1", "2.1.2,2.1.1", "2.1.1,2.1.1", "2.1.10,2.1.1", "2.1.0.2,2.1.1"};
//        for (String testStr : testStrArray) {
//            String[] a = testStr.split(",");
//            String dbVersion = a[0];
//            String currentVersion = a[1];
//            System.out.println(SysUtil.compareVersion(dbVersion, currentVersion));
//        }
//        String mapJsonStr = "{\"0003000008\": \"ICBC\",\"0003000011\": \"DD\",\"0003000010\": \"VIP\",\"0003000014\": \"YHD\",\"0001000699\": \"YHD\",\"0003000091\": \"JD\",\"0000008202\": \"TAOBAO\",\"0003000001\": \"TAOBAO\",\"0000008203\": \"TAOBAO\",\"0000008206\": \"TAOBAO\",\"0003000003\": \"TAOBAO\",\"0000008201\": \"TAOBAO\",\"0003000002\": \"TAOBAO\",\"0003008500\": \"GW\"}";
//        Map<String, String> a = JsonUtil.jsonToStringMap(mapJsonStr);
//        System.out.println("85001100".substring(0, 4) + "-" + "85001100".substring(4));
////        String[] testStrArray = new String[]{"2.1.0,2.1.1", "2.1.2,2.1.1", "2.1.1,2.1.1", "2.1.10,2.1.1", "2.1.0.2,2.1.1"};
////        for (String testStr : testStrArray) {
////            String[] a = testStr.split(",");
////            String dbVersion = a[0];
////            String currentVersion = a[1];
////            System.out.println(SysUtil.compareVersion(dbVersion, currentVersion));
////        }
////        String mapJsonStr ="{\"0003000008\": \"ICBC\",\"0003000011\": \"DD\",\"0003000010\": \"VIP\",\"0003000014\": \"YHD\",\"0001000699\": \"YHD\",\"0003000091\": \"JD\",\"0000008202\": \"TAOBAO\",\"0003000001\": \"TAOBAO\",\"0000008203\": \"TAOBAO\",\"0000008206\": \"TAOBAO\",\"0003000003\": \"TAOBAO\",\"0000008201\": \"TAOBAO\",\"0003000002\": \"TAOBAO\",\"0003008500\": \"GW\"}";
////        Map<String,String> a = JsonUtil.jsonToStringMap(mapJsonStr);
//
////        String jsonStr = "{\"orderBasicInfo\":{\"id\":\"8304705\",\"order_no\":\"118510013787\",\"global_no\":\"\",\"user_id\":\"18510\",\"user_group_id\":\"7\",\"pay_type\":\"6\",\"distribution\":\"1\",\"status\":\"1\",\"pay_status\":\"0\",\"distribution_status\":\"0\",\"back_distribution_status\":\"0\",\"accept_name\":\"闪退\",\"postcode\":\"\",\"telphone\":\"\",\"country\":null,\"province\":\"310000\",\"city\":\"310100\",\"area\":\"310115\",\"address\":\"越溪街道友翔路18号机器人博物馆\",\"mobile\":\"13977788888\",\"payable_amount\":\"1200.00\",\"real_amount\":\"757.33\",\"payable_freight\":\"0.00\",\"real_freight\":\"0.00\",\"pay_time\":null,\"send_time\":null,\"create_time\":\"2016-09-01 16:44:25\",\"completion_time\":null,\"invoice\":\"0\",\"invoice_type\":\"\",\"invoice_amount\":null,\"invoice_title\":\"\",\"invoice_content\":\"\",\"invoice_content_json\":\"\",\"invoice_drawed_amount\":\"0.00\",\"invoice_drawed_amount_json\":null,\"order_from\":\"pc\",\"order_from_detail\":\"\",\"postscript\":\"\",\"note\":null,\"if_del\":\"0\",\"insured\":\"0.00\",\"if_insured\":\"0\",\"pay_fee\":\"0.00\",\"taxes\":\"0.00\",\"promotions\":\"442.67\",\"promotion_id\":\"28\",\"promotion_value\":\"10\",\"wjf_amount\":\"\",\"discount\":\"0.00\",\"exchange_discount\":\"0.00\",\"order_amount\":\"757.33\",\"prop\":\"\",\"accept_time\":\"任意时间,任意时间段\",\"exp\":\"0\",\"point\":\"0\",\"type\":\"0\",\"cancel_reason_id\":\"0\",\"cancel_reason_desc\":\"\",\"trade_no\":null,\"takeself\":\"0\",\"check_status\":\"1\",\"check_remarks\":null,\"check_time_start\":null,\"check_stop_remarks\":null,\"is_stop\":\"0\",\"ecovacs_order_type\":\"0\",\"ecovacs_order_content\":null,\"gift\":null,\"amd_id\":\"0\",\"cf_uid\":\"0\",\"cf_uname\":\"\",\"cf_tid\":\"0\",\"cf_rebate\":\"15.15\",\"cf_bill_status\":\"0\",\"cf_bid\":\"0\",\"cf_btype\":\"0\",\"lock_status\":\"unlock\",\"cf_tpl_rebate\":\"0.00\",\"cf_tbid\":\"0\",\"availablePoint\":\"0\",\"availableSum\":\"0.00\",\"is_cps_order\":\"0\",\"source\":\"site\",\"is_einvoice\":\"0\",\"seckill_id\":\"0\",\"is_old_data\":\"1\"},\"orderGoodsInfo\":[{\"id\":\"47275\",\"order_id\":\"8304705\",\"goods_id\":\"1272\",\"img\":\"upload\\/2015\\/11\\/06\\/20151106094626839.png\",\"product_id\":\"0\",\"goods_price\":\"0.00\",\"real_price\":\"0.00\",\"goods_nums\":\"1\",\"goods_weight\":\"0.00\",\"goods_array\":{\"name\":\"双立人刀具\",\"goodsno\":\"ZJ0713-02 560-CP\",\"ecovacs_goods_no\":\"6922266445057\",\"value\":\"\"},\"is_send\":\"0\",\"is_checkout\":\"0\",\"delivery_id\":\"0\",\"refund_days\":\"0\",\"exchange_days\":\"0\",\"guarantee_days\":\"0\",\"global_no\":\"110-0713-0002\",\"version_desc\":null,\"goods_type\":\"2\",\"refund_nums\":\"1\",\"refund_status\":\"0\",\"exchange_nums\":\"1\",\"exchange_status\":\"0\",\"return_goods_nums\":\"1\",\"return_goods_status\":\"0\",\"maintain_status\":\"0\",\"diy_guide_img\":null,\"diy_guide_title\":null,\"diy_relation_goods_id\":null,\"global_shipping_no\":null,\"platform_args\":null,\"admin_diy_url\":\"\",\"amd_batch_num\":null,\"warehouse_no\":null,\"zero_reason\":\"0\",\"ie_id\":\"0\",\"promotion_price_id\":\"0\"},{\"id\":\"47276\",\"order_id\":\"8304705\",\"goods_id\":\"1273\",\"img\":\"upload\\/2015\\/11\\/06\\/20151106094613830.png\",\"product_id\":\"0\",\"goods_price\":\"0.00\",\"real_price\":\"0.00\",\"goods_nums\":\"1\",\"goods_weight\":\"0.00\",\"goods_array\":{\"name\":\"小熊电热锅\",\"goodsno\":\"ZJ0713-02 560-CP\",\"ecovacs_goods_no\":\"6922266445057\",\"value\":\"\"},\"is_send\":\"0\",\"is_checkout\":\"0\",\"delivery_id\":\"0\",\"refund_days\":\"0\",\"exchange_days\":\"0\",\"guarantee_days\":\"0\",\"global_no\":\"110-0713-0002\",\"version_desc\":null,\"goods_type\":\"2\",\"refund_nums\":\"1\",\"refund_status\":\"0\",\"exchange_nums\":\"1\",\"exchange_status\":\"0\",\"return_goods_nums\":\"1\",\"return_goods_status\":\"0\",\"maintain_status\":\"0\",\"diy_guide_img\":null,\"diy_guide_title\":null,\"diy_relation_goods_id\":null,\"global_shipping_no\":null,\"platform_args\":null,\"admin_diy_url\":\"\",\"amd_batch_num\":null,\"warehouse_no\":null,\"zero_reason\":\"0\",\"ie_id\":\"0\",\"promotion_price_id\":\"0\"},{\"id\":\"47277\",\"order_id\":\"8304705\",\"goods_id\":\"1343\",\"img\":\"upload\\/2016\\/08\\/31\\/20160831084544148.jpg\",\"product_id\":\"0\",\"goods_price\":\"1200.00\",\"real_price\":\"800.33\",\"goods_nums\":\"1\",\"goods_weight\":\"0.00\",\"goods_array\":{\"name\":\"app测试优惠券用商品\",\"goodsno\":\"ZJ0713-02 560-CP\",\"ecovacs_goods_no\":\"6922266445057\",\"value\":\"\"},\"is_send\":\"0\",\"is_checkout\":\"0\",\"delivery_id\":\"0\",\"refund_days\":\"0\",\"exchange_days\":\"0\",\"guarantee_days\":\"0\",\"global_no\":\"110-0713-0002\",\"version_desc\":null,\"goods_type\":\"0\",\"refund_nums\":\"1\",\"refund_status\":\"0\",\"exchange_nums\":\"1\",\"exchange_status\":\"0\",\"return_goods_nums\":\"1\",\"return_goods_status\":\"0\",\"maintain_status\":\"0\",\"diy_guide_img\":null,\"diy_guide_title\":null,\"diy_relation_goods_id\":null,\"global_shipping_no\":null,\"platform_args\":null,\"admin_diy_url\":\"\",\"amd_batch_num\":null,\"warehouse_no\":null,\"zero_reason\":\"0\",\"ie_id\":\"0\",\"promotion_price_id\":\"0\"}],\"orderGoodsSingleInfo\":[{\"id\":\"159693\",\"order_id\":\"8304705\",\"goods_id\":\"1272\",\"product_id\":\"0\",\"order_goods_id\":\"47275\",\"serial_no\":\"472752016090116442579899\",\"send_status\":\"0\",\"after_market_status\":\"0\",\"amd_id\":\"0\",\"delivery_id\":null,\"delivery_no\":null,\"global_shipping_no\":null,\"global_after_market_no\":null,\"global_after_market_asm_no\":null,\"platform_args\":null,\"send_time\":null,\"sn_code\":null},{\"id\":\"159694\",\"order_id\":\"8304705\",\"goods_id\":\"1273\",\"product_id\":\"0\",\"order_goods_id\":\"47276\",\"serial_no\":\"472762016090116442526121\",\"send_status\":\"0\",\"after_market_status\":\"0\",\"amd_id\":\"0\",\"delivery_id\":null,\"delivery_no\":null,\"global_shipping_no\":null,\"global_after_market_no\":null,\"global_after_market_asm_no\":null,\"platform_args\":null,\"send_time\":null,\"sn_code\":null},{\"id\":\"159695\",\"order_id\":\"8304705\",\"goods_id\":\"1343\",\"product_id\":\"0\",\"order_goods_id\":\"47277\",\"serial_no\":\"472772016090116442517603\",\"send_status\":\"0\",\"after_market_status\":\"0\",\"amd_id\":\"0\",\"delivery_id\":null,\"delivery_no\":null,\"global_shipping_no\":null,\"global_after_market_no\":null,\"global_after_market_asm_no\":null,\"platform_args\":null,\"send_time\":null,\"sn_code\":null}],\"orderMapping\":[{\"id\":\"6461\",\"order_id\":\"8304705\",\"order_no\":\"118510013787\",\"new_order_no\":\"11851001378717141906\",\"active\":\"1\",\"time\":\"2016-09-01 17:14:19\",\"pay_status\":\"0\",\"stage\":\"1\",\"type\":\"1\"}]}";
////        GwOrderDetail gwOrderDetail = (GwOrderDetail)JsonUtil.jsonToObject(jsonStr,GwOrderDetail.class);
////        Map<String,String> a = JsonUtil.jsonToStringMap("{\"泰怡凯当当旗舰店\":\"2100005298\",\"科沃斯当当旗舰店\":\"2100005152\"}");
////        System.out.println(a.get(ShopConstants.DD_NICKNAME));
//////        System.out.println(DateUtil.convertDateDateShortToDateLong(DateUtil.DATE_STRING_FORMAT_ALL, new Date()));
//////        System.out.println(DateUtil.getTheDayTime2());
//////        System.out.println(System.currentTimeMillis());
//////        System.out.println(DateUtil.format("yyMMddHHmmssSSS", new Date()));
//////        System.out.println(DateUtil.format("yyMMddHHmm", new Date()));
//////        System.out.println(System.currentTimeMillis() - DateUtil.convertDateStringToDateLong("yyMMddHHmm", DateUtil.format("yyMMddHHmm", new Date())));
////        System.out.println(DateUtil.format(DateUtil.YEAR_MONTH_DATE, DateUtil.getInnerDay(100)));
////        System.out.println(DateUtil.format(DateUtil.YEAR_MONTH_DATE, DateUtil.getInnerDay(-100)));
////        System.out.println(DateUtil.convertDateLongToDateString(DateUtil.DATE_STRING_FORMAT_ALL, 1449725743661l));
////        System.out.println(DateUtil.convertDateLongToDateString(DateUtil.DATE_STRING_FORMAT_ALL, 1453683443522l));
////        System.out.println(DateUtil.convertDateLongToDateString(DateUtil.DATE_STRING_FORMAT_ALL, 1467179518273l));
////        System.out.println(DateUtil.convertDateLongToDateString(DateUtil.DATE_STRING_FORMAT_ALL, 1438216355000l));
////        System.out.println(DateUtil.convertDateLongToDateString(DateUtil.DATE_STRING_FORMAT_ALL, 1472621307394l));
//        System.out.println(DateUtil.convertDateLongToDateString(DateUtil.DATE_STRING_FORMAT_ALL, 1479259106636l));
//        System.out.println(DateUtil.convertDateStringToDateLong(DateUtil.DATE_STRING_FORMAT_ALL, "2016-11-25 00:00:00"));
//        System.out.println(DateUtil.convertDateStringToDateLong(DateUtil.DATE_STRING_FORMAT_ALL, "2016-12-01 00:00:00"));
////        System.out.println(DateUtil.convertDateStringToDateLong(DateUtil.DATE_STRING_FORMAT_ALL, "2016-04-24 00:00:00"));
////        System.out.println(DateUtil.convertDateStringToDateLong(DateUtil.DATE_STRING_FORMAT_ALL, "2015-11-12 00:00:00"));
////        System.out.println(DateUtil.convertDateStringToDateLong(DateUtil.DATE_STRING_FORMAT_ALL, "2015-12-12 00:00:00"));
////////        System.out.println(DateUtil.convertDateLongToDateString(DateUtil.DATE_STRING_FORMAT_ALL, 1438659250151l));
//////        System.out.println(DateUtil.convertDateStringToDateLong(DateUtil.DATE_STRING_FORMAT_ALL, "2015-09-22 16:00:00"));
//////        String a = "{\"AIR\":\"YFSD\",\"BEST\":\"BEST\",\"BHWL\":\"BHWL\",\"CNEX\":\"JJKY\",\"CRE\":\"ZTKY\",\"CYEXP\":\"CYEXP\",\"DBL\":\"DBL\",\"DFH\":\"DFH\",\"DTW\":\"DTWL\",\"EMS\":\"EMS\",\"ESB\":\"ESB\",\"EYB\":\"EYB\",\"FAST\":\"FAST\",\"FEDEX\":\"FedEx\",\"GDEMS\":\"GDEMS\",\"GTO\":\"GTO\",\"GZFY\":\"GZFY\",\"GZLT\":\"GZLT\",\"HOAU\":\"HOAU\",\"HTKY\":\"HTKY\",\"HZABC\":\"HZABC\",\"LB\":\"LB\",\"MGSD\":\"MGSD\",\"OTHER\":\"OTHER\",\"PKGJWL\":\"PKGJWL\",\"POST\":\"POST\",\"POSTB\":\"YZPY\",\"QFKD\":\"QFKD\",\"QRT\":\"ZENY\",\"SF\":\"SF\",\"SHQ\":\"HQ568\",\"STO\":\"STO\",\"SURE\":\"SURE\",\"TTKDEX\":\"HHTT\",\"UAPEX\":\"UAPEX\",\"UC\":\"UC\",\"UNIPS\":\"UNIPS\",\"WND\":\"WND\",\"XB\":\"XBWL\",\"XFWL\":\"XFEX\",\"YANWENBJ\":\"YANWENBJ\",\"YANWENGZ\":\"YANWENGZ\",\"YC\":\"YC\",\"YCT\":\"YCT\",\"YTO\":\"YTO\",\"YUD\":\"YUD\",\"YUNDA\":\"YD\",\"ZJS\":\"ZJS\",\"ZTO\":\"ZTO\",\"ZTOGZ\":\"ZTOGZ\",\"ZTOSH\":\"ZTOSH\"}";
//////        Map<String,String> map = JsonUtil.jsonToStringMap(a);
//////        Map<String,String> map1 = new HashMap<>();
//////        for(Map.Entry<String,String> entry:map.entrySet()){
//////            map1.put(entry.getValue(), entry.getKey());
//////        }
//////        System.out.println(JsonUtil.objectToJson(map1));
//////        String a = "{\"AIR\":\"YFSD\",\"BEST\":\"BEST\",\"BHWL\":\"BHWL\",\"CNEX\":\"JJKY\",\"CRE\":\"ZTKY\",\"CYEXP\":\"CYEXP\",\"DBL\":\"DBL\",\"DFH\":\"DFH\",\"DTW\":\"DTWL\",\"EMS\":\"EMS\",\"ESB\":\"ESB\",\"EYB\":\"EYB\",\"FAST\":\"FAST\",\"FEDEX\":\"FedEx\",\"GDEMS\":\"GDEMS\",\"GTO\":\"GTO\",\"GZFY\":\"GZFY\",\"GZLT\":\"GZLT\",\"HOAU\":\"HOAU\",\"HTKY\":\"HTKY\",\"HZABC\":\"HZABC\",\"LB\":\"LB\",\"MGSD\":\"MGSD\",\"OTHER\":\"OTHER\",\"PKGJWL\":\"PKGJWL\",\"POST\":\"POST\",\"POSTB\":\"YZPY\",\"QFKD\":\"QFKD\",\"QRT\":\"ZENY\",\"SF\":\"SF\",\"SHQ\":\"HQ568\",\"STO\":\"STO\",\"SURE\":\"SURE\",\"TTKDEX\":\"HHTT\",\"UAPEX\":\"UAPEX\",\"UC\":\"UC\",\"UNIPS\":\"UNIPS\",\"WND\":\"WND\",\"XB\":\"XBWL\",\"XFWL\":\"XFEX\",\"YANWENBJ\":\"YANWENBJ\",\"YANWENGZ\":\"YANWENGZ\",\"YC\":\"YC\",\"YCT\":\"YCT\",\"YTO\":\"YTO\",\"YUD\":\"YUD\",\"YUNDA\":\"YD\",\"ZJS\":\"ZJS\",\"ZTO\":\"ZTO\",\"ZTOGZ\":\"ZTOGZ\",\"ZTOSH\":\"ZTOSH\"}";
//////        Map<String,String> map = JsonUtil.jsonToStringMap(a);
//////        Map<String,String> map1 = new HashMap<>();
//////        for(Map.Entry<String,String> entry:map.entrySet()){
//////            map1.put(entry.getValue(), entry.getKey());
//////        }
//////        System.out.println(JsonUtil.objectToJson(map1));
////
////        double a = ArithUtils.div(6576.1d,350);
////        System.out.println(a);
////        double b = ArithUtils.sub(809.19d,a);
////        System.out.println(b);
////        double c = ArithUtils.mul(b,350);
////        System.out.println(c);
////        NumberUtil.isEqual(276640.4d, c, NumberUtil.COMPARE_PRECISION);
//
////        String url = "https://api.weixin.qq.com/sns/userinfo";
////        Map<String, String> params = new HashMap<>();
////        params.put("access_token","SHXb6ArnFvbrj6rjHa4TrfMG3HO3tH0dp4ivQ7-i5yXwGM0Es_s_IYkQ8vvfNDWDf8IESiadCq9iSJwXU9vckKnh-8xkHpVU35NsVrwlolY");
////        params.put("openid", "orD91t5Dk1tRxY_ikNtVxkRVqmOM");
////        HttpResult httpResult = HttpClientUtils.doGet(url, params);
////        httpResult.changeEncode("ISO-8859-1","UTF-8");
////        Map map = (Map)JsonUtil.jsonToObject(httpResult.getBody(),Map.class);
////        System.out.println(SysUtil.objectToString(map.get("headimgurl")));
////        String a = "121467770327009000001^xzhu1986@126.com^朱星星^0.01^S^^201607060095749563^20160706154649|121467770360827001006^xzhu1986@126.com^朱星星^0.01^S^^201607060095749564^20160706154650|";
////        String[] infoArrs= a.split("\\|");
////        if(ArrayUtils.isNotEmpty(infoArrs)){
////            for(String info:infoArrs){
////                //流水号^收款方账号^收款账号姓名^付款金额^成功标识(S)^成功原因(null)^支付宝内部流水号^完成时间。
////                if(SysUtil.isNotEmpty(info)){
////                    String[] values= info.split("\\^");
////                    System.out.println(values[0]);
////                    System.out.println(values[1]);
////                    System.out.println(values[2]);
////                    System.out.println(values[3]);
////                    System.out.println(values[4]);
////                    System.out.println(values[5]);
////                    System.out.println(values[6]);
////                    System.out.println(values[7]);
////                }
////
////            }
////        }
//
////        List<String> orderIdList = new ArrayList<>();
////        orderIdList.add("1145534246179998");
////        orderIdList.add("1109161490724659");
////        orderIdList.add("1162952348223438");
////        orderIdList.add("1145287369809627");
////        orderIdList.add("1161871717135434");
////        orderIdList.add("1105213676112370");
////        orderIdList.add("1139352815952659");
////        orderIdList.add("1142169950071032");
////        orderIdList.add("1163809457984622");
////        orderIdList.add("1152102562145037");
////        Map<String,Object> paramMap = new HashMap<>();
////        paramMap.put("orderIds", orderIdList);
////        paramMap.put("sourceType", "TAOBAO");
////        System.out.println(JsonUtil.objectToJson(paramMap));
////
//// Map map2 = (Map) PHPSerializer.unserialize("a:2:{s:5:\"apiId\";s:9:\"101195697\";s:6:\"apiKey\";s:32:\"82d19abd60cf1486b978a2107a49f1e5\";}".getBytes());
////        for (Object s : map2.keySet()) {
////            System.out.println("key:" + s + " 	 value:" + map2.get(s));
////        }
//
//        String tt = "    snowhitefff@aliyun.com" +
//                " ";
//        System.out.println(trimValue(tt));
//        System.out.println(trimQJValue(tt));
//        Date date = new Date();
//        System.out.println(DateUtil.convertDateToDateString("yyyyMMddHHmmssZZZ", date));
//    }

    /**
     * 将一组String ...arrStr 组装起来
     *
     * @param splitRegex
     * @param arrStr
     * @return
     */
    public static String joinStringArr(String splitRegex, String... arrStr) {
        if (ArrayUtils.isEmpty(arrStr)) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (String str : arrStr) {
            if (StringUtils.isNotEmpty(str)) {
                if (sb.length() > 0 && splitRegex != null) {
                    sb.append(splitRegex);
                }
                sb.append(str);
            }
        }
        return sb.toString();
    }

    public static String join(Collection c, String separator) {
        return StringUtils.join(c, separator);
    }

    public static boolean isStrEqual(String str1, String str2) {
        if (StringUtils.isEmpty(str1) && StringUtils.isEmpty(str2)) {
            return true;
        } else if (StringUtils.isNotEmpty(str1)) {
            return str1.equals(str2);
        }
        return false;
    }

    //abded -> a***d
    public static String encryptStr(final String str) {
        if (StringUtils.isNotEmpty(str)) {
            return StringUtils.substring(str, 0, 1) + "***" + StringUtils.substring(str, str.length() - 1);
        }
        return "";
    }

}
